package com.augurit.wf.client.opinion.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.wf.client.opinion.service.IWfUserOpinionService;
import com.augurit.wf.client.opinion.web.form.WfUserOpinionForm;

public class WfUserOpinionAction extends ExtCrudActionSupport<WfUserOpinionForm>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2329805569813065778L;
	
	private Long id;
	private WfUserOpinionForm form;
	private Long[] ids;
	
	@Autowired
	private IWfUserOpinionService wfUserOpinionService;
	
	
	@Override
	public String delete() throws Exception {
		this.wfUserOpinionService.delete(ids);
		return null;
	}
	
	/**
	 * 清空个人的所有常用意见
	 * @return
	 * @throws Exception
	 */
	public String deleteAllByUserId() throws Exception{
		Long userId = this.getLoginUserId();
		wfUserOpinionService.deleteAllByUserId(userId);
		WfUserOpinionAction.extRenderSuccess();
		return null;
	}
	
	@Override
	public String list() throws Exception {
		Long userId = this.getLoginUserId();
		List<WfUserOpinionForm> list = wfUserOpinionService.getByUserId(userId);
		if(list != null && list.size()>0)
			WfUserOpinionAction.extRenderGridJson(list);
		
		return null;
	}

	@Override
	public String save() throws Exception {
		if(form != null){
			form.setUserId(this.getLoginUserId());
			wfUserOpinionService.save(form);
			WfUserOpinionAction.extRenderSuccess();
		}
		return null;
	}
	
	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			form = wfUserOpinionService.get(id);
		}
		else
			form = new WfUserOpinionForm();
	}
	public WfUserOpinionForm getModel() {
		return form;
	}

	public WfUserOpinionForm getForm() {
		return form;
	}

	public void setForm(WfUserOpinionForm form) {
		this.form = form;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}
	
}
